package com.mengye.test;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;

import jxl.Sheet;
import jxl.Workbook;

import com.mengye.bean.CourseInfoBean;
import com.mengye.control.LoginControl;
import com.mengye.utils.MyUtils;
public class CourseInfoService {

   public List<CourseInfoBean> readExcelData(String filePath){
      List<CourseInfoBean> list = new ArrayList<>();
      try {
         String path = filePath;
         File xlsFile = new File(path);
         FileInputStream fs = new FileInputStream(xlsFile);
         Workbook book = Workbook.getWorkbook(fs);//获取工作簿对象
         Sheet sheet = book.getSheet(0);//获取工作表对象,第一个sheet
         int rows = sheet.getRows();//获取工作表中的数据行数

         for(int i=4;i<=rows-1;i++){//循环Excel工作表的行，并读取单元格数据
            CourseInfoBean c = new CourseInfoBean();
            String date = sheet.getCell(0, i).getContents();
            String time = sheet.getCell(3, i).getContents();
            String name = sheet.getCell(4, i).getContents();
            String place = sheet.getCell(6, i).getContents();
            String con = sheet.getCell(7, i).getContents();
            c.setT_id(LoginControl.user_name);
            c.setC_Date(MyUtils.convertString2Date(date, "yyyy-MM-dd"));
            c.setC_Time(time);
            c.setC_Name(name);
            c.setC_Place(place);
            c.setC_Con(con);
            System.out.println(c.toString());
            list.add(c);
         }
         System.out.println("------获取Excel中的数据【成功】------");
         return list;
      } catch (Exception e) {
         System.out.println("获取Excel中的数据【异常】，异常信息："+e.getMessage());
         e.printStackTrace();
         return null;
      }
   }
   
//   public static void main(String[] args) {
//	List<CourseInfoBean> lst = readExcelData("0");
//	for (CourseInfoBean courseInfoBean : lst) {
//		System.out.println(courseInfoBean.toString());
//	}
//}
}
